/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package fr.irit.etracetool.etrace.impl;

import fr.irit.etracetool.etrace.EObjectOrigin;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import fr.irit.etracetool.etrace.EtracePackage;
import fr.irit.etracetool.etrace.LinkType;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Link Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getDescription <em>Description</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getPurpose <em>Purpose</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getUses <em>Uses</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getExample <em>Example</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getName <em>Name</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getSubType <em>Sub Type</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getSuperType <em>Super Type</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getSourceOrigin <em>Source Origin</em>}</li>
 *   <li>{@link fr.irit.etracetool.etrace.impl.LinkTypeImpl#getTargetOrigin <em>Target Origin</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class LinkTypeImpl extends EObjectImpl implements LinkType {
	/**
	 * The default value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected static final String DESCRIPTION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected String description = DESCRIPTION_EDEFAULT;

	/**
	 * The default value of the '{@link #getPurpose() <em>Purpose</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPurpose()
	 * @generated
	 * @ordered
	 */
	protected static final String PURPOSE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getPurpose() <em>Purpose</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPurpose()
	 * @generated
	 * @ordered
	 */
	protected String purpose = PURPOSE_EDEFAULT;

	/**
	 * The default value of the '{@link #getUses() <em>Uses</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUses()
	 * @generated
	 * @ordered
	 */
	protected static final String USES_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getUses() <em>Uses</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUses()
	 * @generated
	 * @ordered
	 */
	protected String uses = USES_EDEFAULT;

	/**
	 * The default value of the '{@link #getExample() <em>Example</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExample()
	 * @generated
	 * @ordered
	 */
	protected static final String EXAMPLE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getExample() <em>Example</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExample()
	 * @generated
	 * @ordered
	 */
	protected String example = EXAMPLE_EDEFAULT;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getSubType() <em>Sub Type</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubType()
	 * @generated
	 * @ordered
	 */
	protected EList<LinkType> subType;

	/**
	 * The cached value of the '{@link #getSuperType() <em>Super Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSuperType()
	 * @generated
	 * @ordered
	 */
	protected LinkType superType;

	/**
	 * The default value of the '{@link #getSourceOrigin() <em>Source Origin</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSourceOrigin()
	 * @generated
	 * @ordered
	 */
	protected static final EObjectOrigin SOURCE_ORIGIN_EDEFAULT = EObjectOrigin.SOURCE;

	/**
	 * The cached value of the '{@link #getSourceOrigin() <em>Source Origin</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSourceOrigin()
	 * @generated
	 * @ordered
	 */
	protected EObjectOrigin sourceOrigin = SOURCE_ORIGIN_EDEFAULT;

	/**
	 * The default value of the '{@link #getTargetOrigin() <em>Target Origin</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTargetOrigin()
	 * @generated
	 * @ordered
	 */
	protected static final EObjectOrigin TARGET_ORIGIN_EDEFAULT = EObjectOrigin.SOURCE;

	/**
	 * The cached value of the '{@link #getTargetOrigin() <em>Target Origin</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTargetOrigin()
	 * @generated
	 * @ordered
	 */
	protected EObjectOrigin targetOrigin = TARGET_ORIGIN_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LinkTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return EtracePackage.Literals.LINK_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDescription(String newDescription) {
		String oldDescription = description;
		description = newDescription;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__DESCRIPTION, oldDescription, description));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getPurpose() {
		return purpose;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPurpose(String newPurpose) {
		String oldPurpose = purpose;
		purpose = newPurpose;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__PURPOSE, oldPurpose, purpose));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getUses() {
		return uses;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUses(String newUses) {
		String oldUses = uses;
		uses = newUses;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__USES, oldUses, uses));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getExample() {
		return example;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setExample(String newExample) {
		String oldExample = example;
		example = newExample;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__EXAMPLE, oldExample, example));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LinkType> getSubType() {
		if (subType == null) {
			subType = new EObjectWithInverseResolvingEList<LinkType>(LinkType.class, this, EtracePackage.LINK_TYPE__SUB_TYPE, EtracePackage.LINK_TYPE__SUPER_TYPE);
		}
		return subType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public LinkType getSuperType() {
		if (superType != null && superType.eIsProxy()) {
			InternalEObject oldSuperType = (InternalEObject)superType;
			superType = (LinkType)eResolveProxy(oldSuperType);
			if (superType != oldSuperType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EtracePackage.LINK_TYPE__SUPER_TYPE, oldSuperType, superType));
			}
		}
		return superType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public LinkType basicGetSuperType() {
		return superType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSuperType(LinkType newSuperType, NotificationChain msgs) {
		LinkType oldSuperType = superType;
		superType = newSuperType;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__SUPER_TYPE, oldSuperType, newSuperType);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSuperType(LinkType newSuperType) {
		if (newSuperType != superType) {
			NotificationChain msgs = null;
			if (superType != null)
				msgs = ((InternalEObject)superType).eInverseRemove(this, EtracePackage.LINK_TYPE__SUB_TYPE, LinkType.class, msgs);
			if (newSuperType != null)
				msgs = ((InternalEObject)newSuperType).eInverseAdd(this, EtracePackage.LINK_TYPE__SUB_TYPE, LinkType.class, msgs);
			msgs = basicSetSuperType(newSuperType, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__SUPER_TYPE, newSuperType, newSuperType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EObjectOrigin getSourceOrigin() {
		return sourceOrigin;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSourceOrigin(EObjectOrigin newSourceOrigin) {
		EObjectOrigin oldSourceOrigin = sourceOrigin;
		sourceOrigin = newSourceOrigin == null ? SOURCE_ORIGIN_EDEFAULT : newSourceOrigin;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__SOURCE_ORIGIN, oldSourceOrigin, sourceOrigin));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EObjectOrigin getTargetOrigin() {
		return targetOrigin;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTargetOrigin(EObjectOrigin newTargetOrigin) {
		EObjectOrigin oldTargetOrigin = targetOrigin;
		targetOrigin = newTargetOrigin == null ? TARGET_ORIGIN_EDEFAULT : newTargetOrigin;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EtracePackage.LINK_TYPE__TARGET_ORIGIN, oldTargetOrigin, targetOrigin));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EtracePackage.LINK_TYPE__SUB_TYPE:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSubType()).basicAdd(otherEnd, msgs);
			case EtracePackage.LINK_TYPE__SUPER_TYPE:
				if (superType != null)
					msgs = ((InternalEObject)superType).eInverseRemove(this, EtracePackage.LINK_TYPE__SUB_TYPE, LinkType.class, msgs);
				return basicSetSuperType((LinkType)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EtracePackage.LINK_TYPE__SUB_TYPE:
				return ((InternalEList<?>)getSubType()).basicRemove(otherEnd, msgs);
			case EtracePackage.LINK_TYPE__SUPER_TYPE:
				return basicSetSuperType(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case EtracePackage.LINK_TYPE__DESCRIPTION:
				return getDescription();
			case EtracePackage.LINK_TYPE__PURPOSE:
				return getPurpose();
			case EtracePackage.LINK_TYPE__USES:
				return getUses();
			case EtracePackage.LINK_TYPE__EXAMPLE:
				return getExample();
			case EtracePackage.LINK_TYPE__NAME:
				return getName();
			case EtracePackage.LINK_TYPE__SUB_TYPE:
				return getSubType();
			case EtracePackage.LINK_TYPE__SUPER_TYPE:
				if (resolve) return getSuperType();
				return basicGetSuperType();
			case EtracePackage.LINK_TYPE__SOURCE_ORIGIN:
				return getSourceOrigin();
			case EtracePackage.LINK_TYPE__TARGET_ORIGIN:
				return getTargetOrigin();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case EtracePackage.LINK_TYPE__DESCRIPTION:
				setDescription((String)newValue);
				return;
			case EtracePackage.LINK_TYPE__PURPOSE:
				setPurpose((String)newValue);
				return;
			case EtracePackage.LINK_TYPE__USES:
				setUses((String)newValue);
				return;
			case EtracePackage.LINK_TYPE__EXAMPLE:
				setExample((String)newValue);
				return;
			case EtracePackage.LINK_TYPE__NAME:
				setName((String)newValue);
				return;
			case EtracePackage.LINK_TYPE__SUB_TYPE:
				getSubType().clear();
				getSubType().addAll((Collection<? extends LinkType>)newValue);
				return;
			case EtracePackage.LINK_TYPE__SUPER_TYPE:
				setSuperType((LinkType)newValue);
				return;
			case EtracePackage.LINK_TYPE__SOURCE_ORIGIN:
				setSourceOrigin((EObjectOrigin)newValue);
				return;
			case EtracePackage.LINK_TYPE__TARGET_ORIGIN:
				setTargetOrigin((EObjectOrigin)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case EtracePackage.LINK_TYPE__DESCRIPTION:
				setDescription(DESCRIPTION_EDEFAULT);
				return;
			case EtracePackage.LINK_TYPE__PURPOSE:
				setPurpose(PURPOSE_EDEFAULT);
				return;
			case EtracePackage.LINK_TYPE__USES:
				setUses(USES_EDEFAULT);
				return;
			case EtracePackage.LINK_TYPE__EXAMPLE:
				setExample(EXAMPLE_EDEFAULT);
				return;
			case EtracePackage.LINK_TYPE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case EtracePackage.LINK_TYPE__SUB_TYPE:
				getSubType().clear();
				return;
			case EtracePackage.LINK_TYPE__SUPER_TYPE:
				setSuperType((LinkType)null);
				return;
			case EtracePackage.LINK_TYPE__SOURCE_ORIGIN:
				setSourceOrigin(SOURCE_ORIGIN_EDEFAULT);
				return;
			case EtracePackage.LINK_TYPE__TARGET_ORIGIN:
				setTargetOrigin(TARGET_ORIGIN_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case EtracePackage.LINK_TYPE__DESCRIPTION:
				return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description);
			case EtracePackage.LINK_TYPE__PURPOSE:
				return PURPOSE_EDEFAULT == null ? purpose != null : !PURPOSE_EDEFAULT.equals(purpose);
			case EtracePackage.LINK_TYPE__USES:
				return USES_EDEFAULT == null ? uses != null : !USES_EDEFAULT.equals(uses);
			case EtracePackage.LINK_TYPE__EXAMPLE:
				return EXAMPLE_EDEFAULT == null ? example != null : !EXAMPLE_EDEFAULT.equals(example);
			case EtracePackage.LINK_TYPE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case EtracePackage.LINK_TYPE__SUB_TYPE:
				return subType != null && !subType.isEmpty();
			case EtracePackage.LINK_TYPE__SUPER_TYPE:
				return superType != null;
			case EtracePackage.LINK_TYPE__SOURCE_ORIGIN:
				return sourceOrigin != SOURCE_ORIGIN_EDEFAULT;
			case EtracePackage.LINK_TYPE__TARGET_ORIGIN:
				return targetOrigin != TARGET_ORIGIN_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (description: ");
		result.append(description);
		result.append(", purpose: ");
		result.append(purpose);
		result.append(", uses: ");
		result.append(uses);
		result.append(", example: ");
		result.append(example);
		result.append(", name: ");
		result.append(name);
		result.append(", sourceOrigin: ");
		result.append(sourceOrigin);
		result.append(", targetOrigin: ");
		result.append(targetOrigin);
		result.append(')');
		return result.toString();
	}

} //LinkTypeImpl
